<template>
  <el-dialog title="新增工序" :visible.sync="show" width="70%">
    <span v-if="form.other">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="工序名称">
          <el-input
            v-model="form.name"
            @focus="$event.currentTarget.select();"
            placeholder="请输入工序名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="form.other.remarks"
            @focus="$event.currentTarget.select();"
            placeholder="请输入备注"
          ></el-input>
        </el-form-item>
      </el-form>
    </span>
    <span slot="footer" class="dialog-footer">
      <el-button @click="show = false">取 消</el-button>
      <el-button type="primary" @click="show = false;send(form)">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: ["fshow", "form"],
  watch: {
    fshow(a) {
      this.show = true;
    }
  },
  data() {
    return {
      show: false
      // form: { name: "", other: { remarks: "" } }
    };
  },
  methods: {
    send(v) {
      const data = {
        cmd: v.id ? 1 : 2,
        val: {
          token: sessionStorage.token,
          table: "process"
        }
      };
      let tmp = this.$del(v, "id");
      if (v.id) tmp.where = { id: v.id };
      data.val = Object.assign(data.val, tmp);
      this.$post(data, res => {
        if (res.result) {
          if (data.cmd === 2) this.$emit("change", 201, res.result, !v.id);
        }
      });
    }
  }
};
</script>

